﻿using Dapper;
using Himp.TaskScheduling.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.Dapper;
using Volo.Abp.EntityFrameworkCore;

namespace Himp.RL
{
    public class SamplePreparationRecDapperRepository: DapperRepository<RLWebDbContext>, ITransientDependency
    {
        public SamplePreparationRecDapperRepository(IDbContextProvider<RLWebDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public virtual async Task<List<string>> GetAllPersonNamesAsync()
        {
            var dbConnection = await GetDbConnectionAsync();
            return (await dbConnection.QueryAsync<string>(
                "select MachineCode from HY_SamplePreparationRec",
                transaction: await GetDbTransactionAsync())
            ).ToList();
        }

        public virtual async Task<int> UpdatePersonNamesAsync(string name)
        {
            var dbConnection = await GetDbConnectionAsync();
            return await dbConnection.ExecuteAsync(
                "update People set Name = @NewName",
                new { NewName = name },
                await GetDbTransactionAsync()
            );
        }
    }
}
